package com.actimize.dao.hibernate;

import java.util.List;

import com.actimize.dao.AccountDao;
import com.actimize.model.Account;

public class AccountDaoHibernate extends GenericDaoHibernate<Account, Long>
		implements AccountDao {

	public AccountDaoHibernate() {
        super(Account.class);
        System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
        
    }
	
	@SuppressWarnings("unchecked")
	public List<Account> getAll() {
		return getHibernateTemplate().find("from Account");
	}

	public Account save(Account object) {
		return this.saveAccount(object);
	}


	public Account saveAccount(Account account) {
		if (log.isDebugEnabled()) {
			log.debug("account's id: " + account.getAccountID());
		}
		getHibernateTemplate().saveOrUpdate(account);
		// necessary to throw a DataIntegrityViolation and catch it in
		// AccountManager
		getHibernateTemplate().flush();
		return account;

	}

	@SuppressWarnings("unchecked")
	public List<Account> getAccountByUserID(Long userID) {
		System.out.println("Dragan ima user id="+userID);
//		 List<Account> tmpList =  getHibernateTemplate().find("from Account where userID=?", userID);    
		 List<Account> tmpList =  getHibernateTemplate().find("from Account");    
		 
		 if (tmpList!=null)
			 return tmpList;
		 else
			 return null;
	}

}
